import 'package:encrypt/encrypt.dart';
import 'package:meePet/utils/LogUtils.dart';

///加解密算法/模式/填充方式 ECB模式只用密钥即可对数据进行加密解密，CBC模式需要添加一个参数iv
class AesEcbPkcs7Util {
  ///加密
  static String encrypt(String content, String key) {
    LogUtils.i("加密的原始数据是:" + content + "，Key是：" + key);
    Encrypter encrypter =
        Encrypter(AES(Key.fromUtf8(key), mode: AESMode.ecb, padding: "PKCS7"));
    String encrypted = encrypter.encrypt(content).base16;
    LogUtils.i("加密的后的数据是:" + encrypted);
    return encrypted;
  }

  ///解密
  static String decrypt(String content, String key) {
    LogUtils.i("解密的原始数据是:" + content + "，Key是：" + key);
    Encrypter encrypter = Encrypter(AES(Key.fromUtf8(key), mode: AESMode.ecb));
    String decrypted = encrypter.decrypt(Encrypted.fromBase16(content));
    LogUtils.i("解密后的数据是:" + decrypted);
    return decrypted;
  }
}
